package xyz.hzxiao.consumer;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import xyz.hzxiao.UserEntity;
import xyz.hzxiao.api.SayHelloApi;
import xyz.hzxiao.api.UserApi;
import xyz.hzxiao.pojo.UserModel;

/**
 * sayHello消费者
 *
 * @author ：FuXx
 * @className : xyz.hzxiao.consumer.SayHelloConsumer
 * @since ：2023-05-12
 */
@Component
public class SayHelloConsumer {

    @DubboReference(interfaceClass = SayHelloApi.class, check = false)
    private SayHelloApi sayHelloApi;

    @DubboReference(interfaceClass = UserApi.class, check = false, timeout = 3000, retries = 0)
    private UserApi userApi;

    /**
     * 返回jdk自带类型
     */
    public String sayHello(String name) {
        return sayHelloApi.sayHello(name);
    }

    /**
     * 返回自定义对象
     */
    public UserModel findUser(String name) {
        return sayHelloApi.findUserByName(name);
    }

    /**
     * 数据库搜索返回
     */
    public UserEntity findUserById(Long id) {
        return userApi.findUserById(id);
    }

    /**
     * spring事务测试
     */
    public boolean saveNewUser(UserEntity entity) {
        return userApi.saveNewUser(entity);
    }
}
